package com.itheima.chap01;

public class MemoryAllocationDemo {
    public static void main(String[] args) {
        int num1 = 10;
        int num2 = num1;
        System.out.println(num2);//10
        num2 = 20;
        System.out.println(num1);//10


        Girl girl1 =  new Girl();
        girl1.name = "小丽";
        girl1.height = 164;
        girl1.weight = 44;
        System.out.println("girl1.name :" + girl1.name);
        System.out.println("girl1.height :" + girl1.height);
        System.out.println("girl1.weight :" + girl1.weight);//44.0
        Girl girl2 = girl1;
        System.out.println("girl1.name :" + girl2.name);
        System.out.println("girl1.height :" + girl2.height);
        System.out.println("girl1.weight :" + girl2.weight);//44.0

        girl2.weight = 46;
        System.out.println("girl1.name :" + girl1.name);
        System.out.println("girl1.height :" + girl1.height);
        System.out.println("girl1.weight :" + girl1.weight);//46.0
    }
}
/**
 * 笔记：
 * 1.基本类型的内存结构是单独存在于栈当中的，它们独立存在，互不干扰
 * 所以就算num1赋值给num2后，num1和num2的值是独立的，哪怕去修改num2的值，num1的值不会改变
 * 2.引用类型的内存结构是存放在堆中的，它们在栈当中引用的只是堆当中的地址，故而girl1赋值给girl2的只是girl1在堆中的地址
 * 所以当对girl2的值修改时，它会顺着地址到堆中去修改girl1的值，继而使得girl1的值也发生改变
 */